/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.model.service;

import com.model.domain.ubicacion.Departamento;
import com.model.domain.ubicacion.Distrito;
import com.model.domain.ubicacion.Provincia;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;


/**
 *
 * @author Rdelacruz
 */
public class ProvinciaService 
extends AbstractService
{

    public List<Provincia> findByDepartamento(Connection con, String codigoDepartamento) throws SQLException {
        List<Provincia> lista = new ArrayList<Provincia>();
        Statement st = null;
        try {                        
            st = con.createStatement();
            String sql = "select * from Prov where ccdd='"+codigoDepartamento+"'";
            ResultSet rs = st.executeQuery(sql);            
            while(rs.next()) {
                Departamento dep = new Departamento();
                dep.setCodigo(rs.getString("ccdd"));
                
                Provincia prov = new Provincia();
                prov.setCodigo(rs.getString("ccpp"));
                prov.setNombre(rs.getString("nombrePV").toUpperCase());
                prov.setDepartamento(dep);
                lista.add(prov);
            }
        }
        finally {
            if(st!=null) st.close();
        }
        return lista;
    }

    
    
}
